<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mailer extends MY_Controller {
	function __construct() {
		parent::__construct();
	}
	
	public function index() {
		$post_data = $this->input->post("data");
		
		foreach ($post_data as $v) {
			$data[$v['name']] = $v['value'];
		}
		
		$this->load->library('email');
		
		$this->email->from(SMTP_USER, MAILER_FROM_NAME);
		$this->email->reply_to($data['email'], $data['name']);
		$this->email->to(ADMIN_EMAIL);
		
		$this->email->subject($data['name'] . ' - 在线留言');
		
		$this->load->view('mailer.php', $data);
		$output_stream = $this->output->get_output();
		
		$this->email->message($output_stream);
		
		$this->email->send();
	}
}